package com.onefinger.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.onefinger.aspect.Cache;
import com.onefinger.aspect.Uncache;
import com.onefinger.domain.Category;
import com.onefinger.repository.GenericRepository;

public class CategoryService implements ICategoryService {

	@Autowired
	GenericRepository<Category> genericRepository; 
	
	@Autowired
	ILanguageService languageService;
	
	@Cache(cacheKey="categories", expireTime=0)
	public List<Category> list() {
		return genericRepository.getList(Category.class);
	}

	
	@Uncache(cacheKey="categories")
	public boolean save(Category category) {
		try {
			genericRepository.save(category);
			languageService.updateAllVersions();
		} catch (Exception e) {
			
			return false;
		}
		return true;
	}

	@Uncache(cacheKey="categories")
	public boolean remove(Category category) {
		try {
			genericRepository.remove(category);
			languageService.updateAllVersions();
		} catch (Exception e) {
			
			return false;
		}
		return true;
	}

}
